/* Copyright (C) 2011  Kashif Shah, kashifshah.net

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

package net.kashifshah.assistant;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class Chronoclasm extends TabActivity {
    
	private static final String USER_NAME = "Kashif";
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.front);
        
       /* String greeting = getString(R.string.hello,USER_NAME,getString(R.string.app_name));
        TextView greet = (TextView) findViewById(R.id.HelloText);
        greet.setText(greeting);
        */
        
        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, TabChrono.class);

        // Initialize a TabSpec for each tab and add it to the TabHost  
        spec = tabHost.newTabSpec("chrono").setIndicator("Chrono",
        				  res.getDrawable(R.drawable.ic_tab_chrono))
                	  .setContent(intent);
        tabHost.addTab(spec);
        
        // Do the same for the rest of the tabs
        intent = new Intent().setClass(this, TabTask.class);
        spec = tabHost.newTabSpec("tasks").setIndicator("Tasks",
        				  res.getDrawable(R.drawable.ic_tab_task))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, TabProject.class);
        spec = tabHost.newTabSpec("projects").setIndicator("Projects",
                          res.getDrawable(R.drawable.ic_tab_project))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, TabGoal.class);
        spec = tabHost.newTabSpec("goals").setIndicator("Goals",
                          res.getDrawable(R.drawable.ic_tab_goal))
                      .setContent(intent);
        tabHost.addTab(spec);
        
        intent = new Intent().setClass(this, TabProgress.class);
        spec = tabHost.newTabSpec("progress").setIndicator("Progress",
        				  res.getDrawable(R.drawable.ic_tab_progress))
                      .setContent(intent);
        tabHost.addTab(spec);
        
        tabHost.setCurrentTab(0);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.front_menu, menu);
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	// Handle item selection
    	switch (item.getItemId()) {
    	case R.id.frontMenuToCreateGoal:
    		Intent intentCreateGoal = new Intent(this, CreateGoal.class);
    		intentCreateGoal.putExtra("id", "createGoal");
    		startActivity(intentCreateGoal);
    		return true;
    	case R.id.frontMenuToCreateProject:
    		Intent intentCreateProject = new Intent(this, CreateProject.class);
    		intentCreateProject.putExtra("id", "createProject");
    		startActivity(intentCreateProject);
    		return true;
    	case R.id.frontMenuToCreateTask:
    		Intent intentCreateTask = new Intent(this, CreateTask.class);
    		intentCreateTask.putExtra("id", "createTask");
    		startActivity(intentCreateTask);
    		return true;
    	case R.id.frontMenuToEditGoal:
    		Intent intentEditGoal = new Intent(this, EditGoal.class);
    		intentEditGoal.putExtra("id", "editGoal");
    		startActivity(intentEditGoal);
    		return true;
    	case R.id.frontMenuToEditProject:
    		Intent intentEditProject = new Intent(this, EditProject.class);
    		intentEditProject.putExtra("id", "editProject");
    		startActivity(intentEditProject);
    		return true;
    	case R.id.frontMenuToEditTask:
    		Intent intentEditTask = new Intent(this, EditTask.class);
    		intentEditTask.putExtra("id", "editTask");
    		startActivity(intentEditTask);
    		return true;
    	default:
    		return super.onOptionsItemSelected(item);
    	}
    }
}